package cn.francis.encrypt.aspect;

import cn.francis.encrypt.interceptor.EncryptInterceptor;
import cn.hutool.core.util.ArrayUtil;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

/**
 * @author 张俊辉
 */

@Aspect
@RequiredArgsConstructor
public class EncryptAspect {

    private final EncryptInterceptor encryptInterceptor;

    @SneakyThrows
    @Before("@annotation(cn.francis.encrypt.annotation.EncryptMethod)")
    public void before(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        if (ArrayUtil.isEmpty(args)) {
            return;
        }
        for (Object arg : args) {
            encryptInterceptor.disposeEntity(arg);
        }
    }
}
